﻿CREATE PROCEDURE [acms].[PostMenu_Put]
	@PostId int, 
	@MenuId int,
	@Included bit,
	@VersionId timestamp,
	@VersionIdOut timestamp output
	
AS
	if Exists(select null from PostMenu with (nolock) where PostId = @PostId and MenuId = @MenuID and Deleted = 0) begin
		update PostMenu
		set Included = @Included
		where PostId = @PostId and MenuId = @MenuID and VersionId = @VersionId
		if(@@RowCount = 0)
			return -100
	end
	else begin
		insert into PostMenu
			(PostId, MenuId, Included)
		values
			(@PostId, @MenuId, @Included)
		
	end
 	
 	Update Posts Set RequiresPublishing = 1 where Id = @PostId
	
	select @VersionIdOut = VersionId from PostMenu_View with (nolock) where PostId = @PostId and MenuId = @MenuID
RETURN 0;